package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.system.domain.EmploymentTracking;
import com.ruoyi.system.mapper.EmploymentTrackingStudentMapper;
import com.ruoyi.system.domain.EmploymentTrackingStudent;
import com.ruoyi.system.service.IEmploymentTrackingStudentService;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 就业追踪Service业务层处理
 *
 * @author luofan
 * @date 2024-11-17
 */
@Service
public class EmploymentTrackingStudentServiceImpl implements IEmploymentTrackingStudentService
{
    @Autowired
    private EmploymentTrackingStudentMapper employmentTrackingStudentMapper;

    /**
     * 查询就业追踪
     *
     * @param id 就业追踪主键
     * @return 就业追踪
     */
    @Override
    public EmploymentTrackingStudent selectEmploymentTrackingStudentById(Long studentId)
    {
        return employmentTrackingStudentMapper.selectEmploymentTrackingStudentById(studentId);
    }

    /**
     * 查询就业追踪列表
     *
     * @param employmentTrackingStudent 就业追踪
     * @return 就业追踪
     */
    @Override
    public List<EmploymentTrackingStudent> selectEmploymentTrackingStudentList(EmploymentTrackingStudent employmentTrackingStudent, Long uid)
    {
        return employmentTrackingStudentMapper.selectEmploymentTrackingStudentList(employmentTrackingStudent,uid);
    }

    /**
     * 新增就业追踪
     *
     * @param employmentTrackingStudent 就业追踪
     * @return 结果
     */
    @Transactional
    @Override
    public int insertEmploymentTrackingStudent(EmploymentTrackingStudent employmentTrackingStudent)
    {
        int rows = employmentTrackingStudentMapper.insertEmploymentTrackingStudent(employmentTrackingStudent);
        insertEmploymentTracking(employmentTrackingStudent);

        return rows;
    }

    /**
     * 修改就业追踪
     *
     * @param employmentTrackingStudent 就业追踪
     * @return 结果
     */
    @Transactional
    @Override
    public int updateEmploymentTrackingStudent(EmploymentTrackingStudent employmentTrackingStudent)
    {
        employmentTrackingStudentMapper.deleteEmploymentTrackingByStudentId(employmentTrackingStudent.getStudentId());
        insertEmploymentTracking(employmentTrackingStudent);
        return employmentTrackingStudentMapper.updateEmploymentTrackingStudent(employmentTrackingStudent);
    }

    /**
     * 批量删除就业追踪
     *
     * @param ids 需要删除的就业追踪主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEmploymentTrackingStudentByIds(Long[] ids)
    {
        employmentTrackingStudentMapper.deleteEmploymentTrackingByStudentIds(ids);
        return employmentTrackingStudentMapper.deleteEmploymentTrackingStudentByIds(ids);
    }

    /**
     * 删除就业追踪信息
     *
     * @param id 就业追踪主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteEmploymentTrackingStudentById(Long id)
    {
        employmentTrackingStudentMapper.deleteEmploymentTrackingByStudentId(id);
        return employmentTrackingStudentMapper.deleteEmploymentTrackingStudentById(id);
    }

    /**
     * 新增就业追踪信息
     *
     * @param employmentTrackingStudent 就业追踪对象
     */
    public void insertEmploymentTracking(EmploymentTrackingStudent employmentTrackingStudent)
    {
        List<EmploymentTracking> employmentTrackingList = employmentTrackingStudent.getEmploymentTrackingList();
        Long studentId = employmentTrackingStudent.getStudentId();
        if (StringUtils.isNotNull(employmentTrackingList))
        {
            List<EmploymentTracking> list = new ArrayList<EmploymentTracking>();
            for (EmploymentTracking employmentTracking : employmentTrackingList)
            {
                employmentTracking.setStudentId(studentId);
                list.add(employmentTracking);
            }
            if (list.size() > 0)
            {
                employmentTrackingStudentMapper.batchEmploymentTracking(list);
            }
        }
    }
}
